package com.starhub.api.auth.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.starhub.api.auth.result.AuthInfoResult;
import com.starhub.base.auth.entity.AuthInfo;
import com.starhub.base.auth.service.AuthInfoService;
import com.starhub.engine.sys.user.service.SysUserService;
import com.starhub.utils.DateUtil;

/**
 * 认证信息获取
 */
@Service
public class AuthService {

    @Autowired
    private AuthInfoService authInfoService;

    @Autowired
    private SysUserService sysUserService;
    
    /**
     * 获取认证信息
     * @return
     */
    public AuthInfoResult getAuthInfo() {
        // 获取认证信息
        AuthInfo authInfo = authInfoService.getAuthInfo();

        // 获取有效用户数量
        int userCount = sysUserService.countValidUsers();
        
        return AuthInfoResult.success(
            authInfo.getAuthUser(), 
            authInfo.getAuthCode(), 
            DateUtil.formatDate(authInfo.getExpireDate(), DateUtil.f_ymd_Str), 
            userCount, 
            authInfo.getUserLimit(), 
            authInfo.getSystemVersion()
        );
    }
}
